home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.5)
-
- from __future__ import with_statement
- from util import dictadd, boolify as bool_from_string
- import wx.lib.mixins.listctrl as wx
- from wx.lib.mixins.listctrl import ListCtrlAutoWidthMixin
- from wx import VERTICAL, HORIZONTAL, ALIGN_CENTER, TOP, BOTTOM, LEFT, RIGHT, EXPAND, ALL, ALIGN_CENTER, FONTWEIGHT_BOLD, WXK_DOWN
- from prefsdata import *
-
- class PrefsViewer(wx.Panel):
- columns = ('Preference Name', 'Status', 'Type', 'Value')
-
- def __init__(self, parent, prefs, defaults):
- wx.Panel.__init__(self, parent, -1)
- self.prefs = prefs
- self.defaults = defaults
- self.construct_gui()
- prefs.add_observer(self.pref_changed)
- parent.Bind(wx.EVT_CLOSE, self.on_frame_closed)
- self.sort = (0, False)
- self.on_filter_txt()
- self.prefs_list.SetColumnWidth(0, -1)
- if wx.Platform != '__WXMAC__':
- offset = -10
- else:
- offset = -25
- self.prefs_list.SetColumnWidth(0, self.prefs_list.GetColumnWidth(0) + offset)
-
-
- def pref_changed(self, source, pref, old, new):
- wx.CallAfter(self.on_filter_txt)
-
-
- def on_frame_closed(self, e = None):
- self.Hide()
- self.prefs.remove_observer(self.pref_changed)
- e.Skip(True)
-
-
- def filtered_prefs(self, substr = ''):
- sum = dictadd(self.defaults, self.prefs)
- substr = substr.lower()
- remove_these_keys = _[1]
- for key in remove_these_keys:
- sum.pop(key)
-
- return sum
-
-
- def construct_gui(self):
- self.filter_txt = wx.TextCtrl(self, -1)
- [ self.filter_txt.Bind(e, m) for e, m in [
- (wx.EVT_TEXT, self.on_filter_txt),
- (wx.EVT_KEY_DOWN, self.on_filter_text_key)] ]
- self.prefs_list = PrefsListCtrl(self)
- for e, m in [
- (wx.EVT_LIST_ITEM_ACTIVATED, self.on_dclick),
- (wx.EVT_LIST_COL_CLICK, self.on_col_click),
- (wx.EVT_RIGHT_UP, self.on_right_up),
- (wx.EVT_RIGHT_DOWN, self.on_right_down)]:
- self.prefs_list.Bind(e, m)
-
- for i in xrange(len(self.columns)):
- self.prefs_list.InsertColumn(i, self.columns[i])
-
- self.show_all = wx.Button(self, -1, 'Sho&w All')
- self.show_all.Bind((wx.EVT_BUTTON,), (lambda e: None if self.filter_txt.GetValue() != '' else None))
- self.add_new = wx.Button(self, -1, '&Add')
- self.add_new.Bind(wx.EVT_BUTTON, self.add_new_pref)
- hbox = wx.BoxSizer(HORIZONTAL)
- hbox.AddMany([
- (wx.StaticText(self, -1, 'Filter:', style = ALIGN_CENTER), 0, TOP | LEFT | BOTTOM | ALIGN_CENTER, 8),
- (self.filter_txt, 100, EXPAND | ALL, 8),
- (self.show_all, 0, TOP | BOTTOM, 8),
- (self.add_new, 0, TOP | BOTTOM | RIGHT, 8)])
- vbox = wx.BoxSizer(VERTICAL)
- vbox.AddMany([
- (hbox, 0, EXPAND),
- (self.prefs_list, 1, EXPAND)])
- self.SetSizer(vbox)
-
- def foo(e):
- print e
-
- self.Bind(wx.EVT_BUTTON, foo)
-
-
- def add_new_pref(self, e):
- key = str(wx.GetTextFromUser('Please enter the name for the pref', 'Add pref', self.filter_txt.Value))
- if not key:
- return None
-
- typ = str(wx.GetSingleChoice('Please choose the type for the pref', 'Add pref', nice_type_names.values()))
- if not typ:
- return None
-
- typ = nice_name_types[typ]
- if typ is list:
- edit_string_list = edit_string_list
- import gui.toolbox
- (ok, val) = edit_string_list(self, [
- typ()], 'Editing %s' % key)
- if not ok:
- return None
-
- else:
- val = str(wx.GetTextFromUser('Please enter the value for the pref', 'Add pref'))
- val = None if typ is bool else typ(val)
- if val == '':
- return None
-
- self.prefs[key] = val
-
-
- def on_filter_txt(self, e = None):
- self.update_list(self.filtered_prefs(self.filter_txt.Value))
-
-
- def get_default_string(self, key):
-
- try:
- val = self.prefs[key]
- except KeyError:
- return 'default'
-
- return None if val == self.defaults.get(key, sentinel) else 'user-set'
-
-
- def update_list(self, prefs_dict, n = -1):
- self.shown = []
- append = self.shown.append
- plist = self.prefs_list
- sel = plist.GetFirstSelected()
- getdefstr = self.get_default_string
- plist.Frozen().__enter__()
-
- try:
- plist.DeleteAllItems()
- SetStringItem = plist.SetStringItem
- for key, value in enumerate(prefs_dict.iteritems()):
- def_string = getdefstr(key)
- plist.InsertStringItem(i, key)
- SetStringItem(i, 1, def_string)
- SetStringItem(i, 2, nice_type_names[type(value)])
- SetStringItem(i, 3, str(value))
- plist.SetItemData(i, i)
- append((key, value))
- i += 1
-
- plist.SortItems(self.on_sort)
- if sel != -1:
- plist.EnsureVisible(sel)
- finally:
- pass
-
-
-
- def on_filter_text_key(self, e):
- if e.KeyCode == WXK_DOWN:
- self.prefs_list.SetFocus()
- else:
- e.Skip(True)
-
-
- def on_col_click(self, e):
- c = e.GetColumn()
- if c == self.sort[0]:
- ascending = not self.sort[1]
- else:
- ascending = False
- self.sort = (c, ascending)
- self.prefs_list.SortItems(self.on_sort)
-
-
- def on_sort(self, one, two):
- one = self.shown[one]
- two = self.shown[two]
- (column, ascending) = self.sort
-
- ({
- 0: (lambda x: x[0]),
- 2: (lambda x: nice_type_names[type(x[1])]),
- 3: (lambda x: str(x[1])) },)[1] = lambda x: self.get_default_string(x[0])
- _cmp = {
- 0: (lambda x: x[0]),
- 2: (lambda x: nice_type_names[type(x[1])]),
- 3: (lambda x: str(x[1])) }.get(column, None)
- return ascending == _cmp(one) < _cmp(two)
-
-
- def on_dclick(self, e):
- key = e.GetText()
- get = get
- import util
- mysentinel = Sentinel()
- defval = get(self.defaults, key, mysentinel)
- val = self.prefs.setdefault(key, defval)
- if isinstance(defval, bool):
- val = not val
- elif isinstance(defval, list):
- if is_all(val, (str, unicode))[0]:
- (ok, new_list) = edit_string_list(self, val, 'Editing ' + key)
- if ok:
- val = new_list
-
- else:
- print is_all(val)
- raise AssertionError, key + ' is not a homogenous list :( tell Kevin to make this more gooder'
- elif isinstance(defval, (str, unicode, int, float)) or defval is mysentinel:
- t = None if defval is mysentinel else type(defval)
- print 'editing pref of type', t
- diag = wx.TextEntryDialog(self, key, 'Enter %s' % nice_type_names[t], str(val))
- if diag.ShowModal() == wx.ID_OK:
- val = diag.GetValue()
- if t is bool:
- val = bool_from_string(val)
-
- if val == '':
- self.prefs[str(key)] = self.defaults[str(key)]
- return self.on_filter_txt()
- elif defval is not mysentinel:
- val = t(val)
-
-
-
- self.prefs[str(key)] = val
- self.on_filter_txt()
-
-
- def on_right_up(self, e):
- i = self.prefs_list.GetFirstSelected()
-
-
- def on_right_down(self, e):
- e.Skip(True)
-
-
-
- class PrefsFrame(wx.Frame):
-
- def __init__(self, prefs, defaults, parent = None, id = -1, title = 'Advanced Preferences', name = 'Advanced Preferences'):
- wx.Frame.__init__(self, parent, id, title, style = wx.DEFAULT_FRAME_STYLE | wx.FRAME_NO_TASKBAR & ~(wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX))
- self.prefs_viewer = PrefsViewer(self, prefs, defaults)
- persist_window_pos = persist_window_pos
- snap_pref = snap_pref
- import gui.toolbox
- persist_window_pos(self, unique_id = 'PrefsFrame', defaultrect = (lambda : wx.Rect(100, 100, 600, 500)))
- snap_pref(self)
-
-
-
- class PrefsListCtrl(wx.ListCtrl, ListCtrlAutoWidthMixin):
- list_style = wx.LC_REPORT | wx.SUNKEN_BORDER | wx.LC_SINGLE_SEL
-
- def __init__(self, parent, id = -1, style = None):
- if not style:
- pass
- wx.ListCtrl.__init__(self, parent, id, style = self.list_style)
- ListCtrlAutoWidthMixin.__init__(self)
-
-
-
- def edit(prefs, defaults, parent = None):
- for win in wx.GetTopLevelWindows():
- if isinstance(win, PrefsFrame):
- return win.Close()
- continue
-
- f = PrefsFrame(parent = parent, prefs = prefs, defaults = defaults)
- wx.CallAfter(f.Show)
-
-